package com.hhw.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.hhw.entity.Order;
import com.hhw.util.DBUtil;

public class OrderPageDao {

	
	
	/*统计共有多少条数据根据<id>*/
	public int findOrderPage(){
		try{
			Connection con=DBUtil.getConnection();
			PreparedStatement pstm=con.prepareStatement("select count(order_id) from orderlist");
			ResultSet rs=pstm.executeQuery();
			int count=0;
			while(rs.next()){
				count=rs.getInt(1);
			}
			return count;
		}catch(Exception e){
			e.printStackTrace();
			return 0;
		}
	}
	
	
	   /*   订单翻页查询*/
	public List<Order> findOrderByPage(int orderpageNum, int orderpageSize){
		try{
			List<Order> list=new ArrayList<Order>();
			Connection con=DBUtil.getConnection();
			PreparedStatement pstm=con.prepareStatement("select * from orderlist limit ?,?");
			pstm.setInt(1, (orderpageNum-1)*orderpageSize);
			pstm.setInt(2, orderpageSize);
			ResultSet rs=pstm.executeQuery();
			Order p=null;
			while(rs.next()){
				p=new Order();
				p.setOrder_id(rs.getInt(1));
				p.setOrder_name(rs.getString(2));
				p.setOrder_price(rs.getString(3));
				p.setOrder_count(rs.getString(4));
				p.setOrder_money(rs.getString(5));
				list.add(p);
				System.out.println(p);
			}
			return list;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	
	
	
	
	
	
	
}
